package genericity

// 泛型结构体，只能使用int或string类型
type MyStruct[T interface{ *int | *string }] struct {
	Name string
	Data T
}

// 泛型 receiver
func (myStruct MyStruct[T]) GetData() T {
	return myStruct.Data
}

func ReceiverCase() {
	data := 18
	myStruct := MyStruct[*int]{
		Name: "nick",
		Data: &data,
	}
	data2 := myStruct.GetData()
	println(*data2)

	str := "abcdefg"
	myStruct2 := MyStruct[*string]{
		Name: "nick",
		Data: &str,
	}
	str2 := myStruct2.GetData()
	println(*str2)
}
